home *** CD-ROM | disk | FTP | other *** search
/ Champak 109 / Vol 109.iso / games / athlete_.swf / scripts / frame_30 / DoAction.as
Text File  |  2008-11-12  |  18KB  |  615 lines

  1. function doai()
  2. {
  3.    if(players[1].state == 0)
  4.    {
  5.       bn = nearestball();
  6.       if(bn >= 0)
  7.       {
  8.          if(cpulevel < math.random() * 50)
  9.          {
  10.             ctb = eval("ball" + bn);
  11.             if(ctb._x < pl1._x - players[1].speed)
  12.             {
  13.                if(pl1.legs._currentframe == 1)
  14.                {
  15.                   pl1.legs.gotoAndPlay("walk");
  16.                }
  17.                pl1._x -= players[1].speed;
  18.                if(pl1._x < players[1].mx + pl1._width / 2)
  19.                {
  20.                   pl1._x = players[1].mx + pl1._width / 2;
  21.                }
  22.             }
  23.             else if(pl1._x + players[1].speed < ctb._x)
  24.             {
  25.                if(pl1.legs._currentframe == 1)
  26.                {
  27.                   pl1.legs.gotoAndPlay("walk");
  28.                }
  29.                pl1._x += players[1].speed;
  30.                if(players[1].my - pl1._width / 2 < pl1._x)
  31.                {
  32.                   pl1._x = players[1].my - pl1._width / 2;
  33.                }
  34.             }
  35.          }
  36.       }
  37.       else if(0 < players[1].ballsready.length)
  38.       {
  39.          if(pl1._x < 350)
  40.          {
  41.             if(pl1.legs._currentframe == 1)
  42.             {
  43.                pl1.legs.gotoAndPlay("walk");
  44.             }
  45.             pl1._x += players[1].speed;
  46.             if(players[1].my - pl1._width / 2 < pl1._x)
  47.             {
  48.                pl1._x = players[1].my - pl1._width / 2;
  49.             }
  50.          }
  51.          else
  52.          {
  53.             players[1].ballsloaded.push(players[1].ballsready.pop());
  54.             players[1].ballload = players[1].loadspeed;
  55.             players[1].state = 1;
  56.             players[1].cpuangle = 90 - Math.atan(pl1._y / (pl1._x - 300)) * 57.29577951308232 + (Math.random() * cpulevel - cpulevel / 2);
  57.          }
  58.       }
  59.       else if(pl1._x < balllying())
  60.       {
  61.          if(pl1.legs._currentframe == 1)
  62.          {
  63.             pl1.legs.gotoAndPlay("walk");
  64.          }
  65.          pl1._x += players[1].speed;
  66.          if(players[1].my - pl1._width / 2 < pl1._x)
  67.          {
  68.             pl1._x = players[1].my - pl1._width / 2;
  69.          }
  70.       }
  71.       else if(balllying() < pl1._x)
  72.       {
  73.          if(pl1.legs._currentframe == 1)
  74.          {
  75.             pl1.legs.gotoAndPlay("walk");
  76.          }
  77.          pl1._x -= players[1].speed;
  78.          if(pl1._x < players[1].mx + pl1._width / 2)
  79.          {
  80.             pl1._x = players[1].mx + pl1._width / 2;
  81.          }
  82.       }
  83.    }
  84.    else if(players[1].state == 1)
  85.    {
  86.       if(0 < players[1].ballsready.length && 1 < Math.random() * 10)
  87.       {
  88.          players[1].ballload--;
  89.          if(players[1].ballload == 0)
  90.          {
  91.             if(0 < players[1].ballsready.length)
  92.             {
  93.                players[1].ballsloaded.push(players[1].ballsready.pop());
  94.                players[1].ballload = players[1].loadspeed;
  95.             }
  96.          }
  97.       }
  98.       else
  99.       {
  100.          players[1].state = 2;
  101.       }
  102.    }
  103.    else if(players[1].state == 2)
  104.    {
  105.       players[1].ballload = 0;
  106.       if(pl1.body._rotation >= players[1].cpuangle - 3 && players[1].cpuangle + 3 >= pl1.body._rotation)
  107.       {
  108.          players[1].state = 3;
  109.       }
  110.       else if(0 >= pl1.body._rotation)
  111.       {
  112.          pl1.body._rotation = 0;
  113.          players[1].state = 3;
  114.       }
  115.       else
  116.       {
  117.          pl1.body._rotation -= 5;
  118.       }
  119.    }
  120.    else if(players[1].state == 3)
  121.    {
  122.       if(players[1].ballload == 0)
  123.       {
  124.          if(0 < players[1].ballsloaded.length)
  125.          {
  126.             fireBall.start();
  127.             tb = players[1].ballsloaded.pop();
  128.             ty = players[1].scale * (0 + 52 * Math.sin((pl1.body._rotation - 88) * 0.017453292519943295));
  129.             tx = players[1].scale * (- 52 * Math.cos((pl1.body._rotation - 88) * 0.017453292519943295));
  130.             balls[tb].ystep = 0 + balls[tb].speed * Math.sin((pl1.body._rotation - 90) * 0.017453292519943295);
  131.             balls[tb].xstep = - balls[tb].speed * Math.cos((pl1.body._rotation - 90) * 0.017453292519943295);
  132.             tempb = eval("ball" + tb);
  133.             tempb._x = pl1._x + tx;
  134.             tempb._y = pl1._y + ty;
  135.             if(275 >= tempb._x)
  136.             {
  137.                tempb._x = 279;
  138.                balls[tb].xstep *= -1;
  139.             }
  140.             balls[tb].state = 1;
  141.             balls[tb].hitby = ti;
  142.             pl1.body._rotation -= 8;
  143.             players[1].ballload = players[1].firespeed;
  144.          }
  145.          else
  146.          {
  147.             players[1].ballload = 0;
  148.             players[1].state = 4;
  149.          }
  150.       }
  151.       else
  152.       {
  153.          players[1].ballload--;
  154.       }
  155.    }
  156.    else if(players[1].state == 4)
  157.    {
  158.       if(90 >= pl1.body._rotation)
  159.       {
  160.          pl1.body._rotation += 10;
  161.       }
  162.       else
  163.       {
  164.          pl1.body._rotation = 90;
  165.          players[1].state = 0;
  166.       }
  167.    }
  168. }
  169. function nearestball()
  170. {
  171.    lowest = 0;
  172.    ballnum = -1;
  173.    ci = 0;
  174.    while(ci < ballsout)
  175.    {
  176.       if(balls[ci].state == 1)
  177.       {
  178.          cball = eval("ball" + ci);
  179.          if(270 < cball._x && lowest < cball._y)
  180.          {
  181.             ballnum = ci;
  182.             lowest = cball._y;
  183.          }
  184.       }
  185.       ci++;
  186.    }
  187.    return ballnum;
  188. }
  189. function balllying()
  190. {
  191.    lowest = 3000;
  192.    ci = 0;
  193.    while(ci < ballsout)
  194.    {
  195.       if(balls[ci].state == 20)
  196.       {
  197.          cball = eval("ball" + ci);
  198.          tx = cball._x - pl1._x;
  199.          if(Math.abs(tx) < Math.abs(lowest - pl1._x))
  200.          {
  201.             lowest = cball._x;
  202.          }
  203.       }
  204.       ci++;
  205.    }
  206.    if(lowest == 3000)
  207.    {
  208.       return pl1._x;
  209.    }
  210.    return lowest;
  211. }
  212. ti = 0;
  213. while(ti < maxballs)
  214. {
  215.    if(balls[ti].state == 1)
  216.    {
  217.       tball = eval("ball" + ti);
  218.       balls[ti].ystep += balls[ti].gravity;
  219.       if(90 < tball._y)
  220.       {
  221.          if(tball._x < 275 && tball._x + balls[ti].xstep >= 275)
  222.          {
  223.             tball._x = 271;
  224.             balls[ti].xstep *= -1;
  225.          }
  226.          else if(275 < tball._x && 275 >= tball._x + balls[ti].xstep)
  227.          {
  228.             tball._x = 279;
  229.             balls[ti].xstep *= -1;
  230.          }
  231.       }
  232.       if(tball._x + balls[ti].xstep < 44)
  233.       {
  234.          tball._x = 44;
  235.          balls[ti].xstep *= -1;
  236.       }
  237.       if(510 < tball._x + balls[ti].xstep)
  238.       {
  239.          tball._x = 510;
  240.          balls[ti].xstep *= -1;
  241.       }
  242.       tball._x += balls[ti].xstep;
  243.       tsy = tball._y;
  244.       tball._y += balls[ti].ystep;
  245.       if(pl0.body.funnel.hit.hitTest(tball._x,tball._y,true))
  246.       {
  247.          players[0].ballsready.push(ti);
  248.          balls[ti].state = 0;
  249.          tball._x = -20;
  250.       }
  251.       else if(pl1.body.funnel.hit.hitTest(tball._x,tball._y,true))
  252.       {
  253.          players[1].ballsready.push(ti);
  254.          balls[ti].state = 0;
  255.          tball._x = -20;
  256.       }
  257.       else if(tball._x < 275)
  258.       {
  259.          twall = eval("ground0" + (players[0].height - 1));
  260.          if(twall._y < tball._y)
  261.          {
  262.             balls[ti].state = 10;
  263.             tj = 0;
  264.             while(tj < maxballs)
  265.             {
  266.                if(balls[tj].state == 10)
  267.                {
  268.                   tjball = eval("ball" + tj);
  269.                   tjball._y = twall._y + twall._height - 9;
  270.                }
  271.                tj++;
  272.             }
  273.             twall.removeMovieClip();
  274.             levelGo.start();
  275.             players[0].height -= 1;
  276.             dropcreature(0);
  277.             if(players[0].height == 0)
  278.             {
  279.                gotoAndPlay(36);
  280.             }
  281.          }
  282.       }
  283.       else if(275 < tball._x)
  284.       {
  285.          twall = eval("ground1" + (players[1].height - 1));
  286.          if(twall._y < tball._y)
  287.          {
  288.             balls[ti].state = 20;
  289.             tj = 0;
  290.             while(tj < maxballs)
  291.             {
  292.                if(balls[tj].state == 20)
  293.                {
  294.                   tjball = eval("ball" + tj);
  295.                   tjball._y = twall._y + twall._height - 9;
  296.                }
  297.                tj++;
  298.             }
  299.             twall.removeMovieClip();
  300.             levelGo.start();
  301.             players[1].height -= 1;
  302.             dropcreature(1);
  303.             if(players[1].height == 0)
  304.             {
  305.                gotoAndPlay(33);
  306.             }
  307.          }
  308.          c;
  309.       }
  310.       tk = 0;
  311.       while(tk < tokensout)
  312.       {
  313.          ttok = eval("token" + tk);
  314.          if(ttok.hitTest(tball._x,tball._y,true))
  315.          {
  316.             tokenPop.start();
  317.             tokensout--;
  318.             ttok._x = -100;
  319.             if(ttok._currentframe == 2)
  320.             {
  321.                tbk = eval("ball" + ballsout);
  322.                tbk._x = tball._x;
  323.                tbk._y = tball._y;
  324.                balls[ballsout].xstep = balls[ti].xstep * -1;
  325.                balls[ballsout].ystep = balls[ti].ystep;
  326.                balls[ballsout].state = 1;
  327.                setballtype(ballsout,balls[ti].type);
  328.                ballsout++;
  329.             }
  330.             else if(ttok._currentframe == 3)
  331.             {
  332.                if(balls[ti].type == 1)
  333.                {
  334.                   balls[ti].xstep *= 0.4;
  335.                   balls[ti].ystep *= 0.4;
  336.                }
  337.                if(balls[ti].type == 3)
  338.                {
  339.                   balls[ti].xstep *= 0.2;
  340.                   balls[ti].ystep *= 0.2;
  341.                }
  342.                setballtype(ti,2);
  343.             }
  344.             else if(ttok._currentframe == 4)
  345.             {
  346.                if(balls[ti].type == 2)
  347.                {
  348.                   balls[ti].xstep *= 2;
  349.                   balls[ti].ystep *= 2;
  350.                }
  351.                if(balls[ti].type == 3)
  352.                {
  353.                   balls[ti].xstep *= 0.5;
  354.                   balls[ti].ystep *= 0.5;
  355.                }
  356.                setballtype(ti,1);
  357.             }
  358.             else if(ttok._currentframe == 5)
  359.             {
  360.                if(balls[ti].type == 1)
  361.                {
  362.                   balls[ti].xstep *= 1.5;
  363.                   balls[ti].ystep *= 1.5;
  364.                }
  365.                else if(balls[ti].type == 2)
  366.                {
  367.                   balls[ti].xstep *= 2.6;
  368.                   balls[ti].ystep *= 2.6;
  369.                }
  370.                setballtype(ti,3);
  371.             }
  372.             else if(ttok._currentframe == 6)
  373.             {
  374.                if(1.4 >= players[balls[ti].hitby].scale)
  375.                {
  376.                   players[balls[ti].hitby].scale += 0.2;
  377.                   tpl = eval("pl" + balls[ti].hitby);
  378.                   tpl._xscale = players[balls[ti].hitby].scale * 8;
  379.                   tpl._yscale = players[balls[ti].hitby].scale * 8;
  380.                   tpl._y -= 20;
  381.                   dropcreature(balls[ti].hitby);
  382.                }
  383.             }
  384.             else if(ttok._currentframe == 7)
  385.             {
  386.                hb = (balls[ti].hitby + 1) % 2;
  387.                if(players[hb].scale >= 1)
  388.                {
  389.                   players[hb].scale -= 0.2;
  390.                   tpl = eval("pl" + hb);
  391.                   tpl._xscale = players[hb].scale * 8;
  392.                   tpl._yscale = players[hb].scale * 8;
  393.                   tpl._y -= 20;
  394.                   dropcreature(hb);
  395.                }
  396.             }
  397.          }
  398.          tk++;
  399.       }
  400.       if(0 < tsy && tball._y < 0)
  401.       {
  402.          tarrow.duplicateMovieClip("arrow" + ti,250 + ti);
  403.          tar = eval("arrow" + ti);
  404.          tar.gotoAndStop(balls[ti].type);
  405.       }
  406.       else if(tsy < 0 && 0 < tball._y)
  407.       {
  408.          tar = eval("arrow" + ti);
  409.          tar.removeMovieClip();
  410.       }
  411.       tar = eval("arrow" + ti);
  412.       if(tar != undefined)
  413.       {
  414.          tar._x = tball._x;
  415.          tar._y = 0;
  416.       }
  417.    }
  418.    else if(balls[ti].state == 10)
  419.    {
  420.       tball = eval("ball" + ti);
  421.       if(tball._x < 48)
  422.       {
  423.          tball._x = 48;
  424.       }
  425.       if(263 < tball._x)
  426.       {
  427.          tball._x = 263;
  428.       }
  429.       if(pl0.hitTest(tball))
  430.       {
  431.          players[0].ballsready.push(ti);
  432.          balls[ti].state = 0;
  433.          tball._x = -20;
  434.       }
  435.    }
  436.    else if(balls[ti].state == 20)
  437.    {
  438.       tball = eval("ball" + ti);
  439.       if(500 < tball._x)
  440.       {
  441.          tball._x = 500;
  442.       }
  443.       if(tball._x < 298)
  444.       {
  445.          tball._x = 298;
  446.       }
  447.       if(pl1.hitTest(tball))
  448.       {
  449.          players[1].ballsready.push(ti);
  450.          balls[ti].state = 0;
  451.          tball._x = -20;
  452.       }
  453.    }
  454.    ti++;
  455. }
  456. ti = 0;
  457. while(ti < humanplayers)
  458. {
  459.    if(players[ti].state == 0)
  460.    {
  461.       if(Key.isDown(players[ti].leftk))
  462.       {
  463.          tempp = eval("pl" + ti);
  464.          if(tempp.legs._currentframe == 1)
  465.          {
  466.             tempp.legs.gotoAndPlay("walk");
  467.          }
  468.          tempp._x -= players[ti].speed;
  469.          if(tempp._x < players[ti].mx + tempp._width / 2)
  470.          {
  471.             tempp._x = players[ti].mx + tempp._width / 2;
  472.          }
  473.       }
  474.       if(Key.isDown(players[ti].rightk))
  475.       {
  476.          tempp = eval("pl" + ti);
  477.          if(tempp.legs._currentframe == 1)
  478.          {
  479.             tempp.legs.gotoAndPlay("walk");
  480.          }
  481.          tempp._x += players[ti].speed;
  482.          if(players[ti].my - tempp._width / 2 < tempp._x)
  483.          {
  484.             tempp._x = players[ti].my - tempp._width / 2;
  485.          }
  486.       }
  487.       if(Key.isDown(players[ti].firek))
  488.       {
  489.          if(0 < players[ti].ballsready.length)
  490.          {
  491.             players[ti].ballsloaded.push(players[ti].ballsready.pop());
  492.             players[ti].ballload = players[ti].loadspeed;
  493.             players[ti].state = 1;
  494.          }
  495.       }
  496.    }
  497.    else if(players[ti].state == 1)
  498.    {
  499.       if(Key.isDown(players[ti].firek))
  500.       {
  501.          players[ti].ballload--;
  502.          if(players[ti].ballload == 0)
  503.          {
  504.             if(0 < players[ti].ballsready.length)
  505.             {
  506.                players[ti].ballsloaded.push(players[ti].ballsready.pop());
  507.                players[ti].ballload = players[ti].loadspeed;
  508.             }
  509.          }
  510.       }
  511.       else
  512.       {
  513.          players[ti].state = 2;
  514.       }
  515.    }
  516.    else if(players[ti].state == 2)
  517.    {
  518.       players[ti].ballload = 0;
  519.       tempp = eval("pl" + ti);
  520.       if(Key.isDown(players[ti].firek))
  521.       {
  522.          players[ti].state = 3;
  523.       }
  524.       else if(0 >= tempp.body._rotation)
  525.       {
  526.          tempp.body._rotation = 0;
  527.          players[ti].state = 3;
  528.       }
  529.       else
  530.       {
  531.          tempp.body._rotation -= 5;
  532.       }
  533.    }
  534.    else if(players[ti].state == 3)
  535.    {
  536.       if(players[ti].ballload == 0)
  537.       {
  538.          if(0 < players[ti].ballsloaded.length)
  539.          {
  540.             tb = players[ti].ballsloaded.pop();
  541.             fireBall.start();
  542.             tempp = eval("pl" + ti);
  543.             if(ti == 0)
  544.             {
  545.                ty = players[ti].scale * (0 + 52 * Math.sin((tempp.body._rotation - 88) * 0.017453292519943295));
  546.                tx = players[ti].scale * (0 + 52 * Math.cos((tempp.body._rotation - 88) * 0.017453292519943295));
  547.                balls[tb].ystep = 0 + balls[tb].speed * Math.sin((tempp.body._rotation - 90) * 0.017453292519943295);
  548.                balls[tb].xstep = 0 + balls[tb].speed * Math.cos((tempp.body._rotation - 90) * 0.017453292519943295);
  549.                tempb = eval("ball" + tb);
  550.                tempb._x = tempp._x + tx;
  551.                tempb._y = tempp._y + ty;
  552.                if(tempb._x >= 275)
  553.                {
  554.                   tempb._x = 271;
  555.                   balls[tb].xstep *= -1;
  556.                }
  557.             }
  558.             else
  559.             {
  560.                ty = players[ti].scale * (0 + 52 * Math.sin((tempp.body._rotation - 88) * 0.017453292519943295));
  561.                tx = players[ti].scale * (- 52 * Math.cos((tempp.body._rotation - 88) * 0.017453292519943295));
  562.                balls[tb].ystep = 0 + balls[tb].speed * Math.sin((tempp.body._rotation - 90) * 0.017453292519943295);
  563.                balls[tb].xstep = - balls[tb].speed * Math.cos((tempp.body._rotation - 90) * 0.017453292519943295);
  564.                tempb = eval("ball" + tb);
  565.                tempb._x = tempp._x + tx;
  566.                tempb._y = tempp._y + ty;
  567.                if(275 >= tempb._x)
  568.                {
  569.                   tempb._x = 279;
  570.                   balls[tb].xstep *= -1;
  571.                }
  572.             }
  573.             balls[tb].state = 1;
  574.             balls[tb].hitby = ti;
  575.             tempp.body._rotation -= 8;
  576.             players[ti].ballload = players[ti].firespeed;
  577.          }
  578.          else
  579.          {
  580.             players[ti].ballload = 0;
  581.             players[ti].state = 4;
  582.          }
  583.       }
  584.       else
  585.       {
  586.          players[ti].ballload--;
  587.       }
  588.    }
  589.    else if(players[ti].state == 4)
  590.    {
  591.       tempp = eval("pl" + ti);
  592.       if(90 >= tempp.body._rotation)
  593.       {
  594.          tempp.body._rotation += 10;
  595.       }
  596.       else
  597.       {
  598.          tempp.body._rotation = 90;
  599.          players[ti].state = 0;
  600.       }
  601.    }
  602.    ti++;
  603. }
  604. if(humanplayers < 2)
  605. {
  606.    doai();
  607. }
  608. pl0.body.funnel.gotoAndStop(players[0].ballsready.length + 1);
  609. tbll = eval("pl0.body.funnel.ball" + (players[0].ballsready.length - 1));
  610. tbll.gotoAndStop(balls[players[0].ballsready[players[0].ballsready.length - 1]].type);
  611. pl1.body.funnel.gotoAndStop(players[1].ballsready.length + 1);
  612. tbll = eval("pl1.body.funnel.ball" + (players[1].ballsready.length - 1));
  613. tbll.gotoAndStop(balls[players[1].ballsready[players[1].ballsready.length - 1]].type);
  614. placetoken();
  615.